import BaseApi from "@/api/BaseApi.ts";
import type IPageResp from "@/type/IPageResp.ts";
import type ISysUserReq from "../type/req/ISysUserReq.ts";
import type ISysUserResp from "../type/resp/ISysUserResp.ts";
import type ISysUserRoleResp from "@/view/rbac/user/type/resp/ISysUserRoleResp.ts";
import type ISysDepartResp from "@/view/depart/type/resp/ISysDepartResp.ts";
import type CheckPasswordReq from "@/view/rbac/user/type/req/CheckPasswordReq.ts";
import type RefreshPasswordReq from "@/view/rbac/user/type/req/RefreshPasswordReq.ts";

class UserApi extends BaseApi {
    constructor() {
        super('/rbac/user')
    }

    /**
     * 分页查询用户列表
     */
    page = (userReq: ISysUserReq) => {
        return this.get<IPageResp<ISysUserResp>, ISysUserReq>('page', userReq)
    }

    /**
     * 根据有无id新增或编辑用户
     */
    addOrUpdate = (userReq: ISysUserReq) => {
        return this.post<string, ISysUserReq>('addOrUpdate', userReq)
    }

    /**
     * 修改用户状态
     */
    status = (status: { id: string, status: number }) => {
        return this.get<string, { id: string, status: number }>('status', status)
    }

    /**
     * 根据id查询用户
     */
    queryById = (id: String) => {
        return this.get('queryById', {id})
    }

    /**
     * 根据id删除用户
     */
    deleteById = (ids: string[]) => {
        return this.delete<string>('delete', ids)
    }

    /**
     * 根据id删除用户
     */
    listUserRoles = (params: { userId: string, departIds: string, roleName: string, roleCode: string }) => {
        return this.get<ISysUserRoleResp[], {
            userId: string,
            departIds: string,
            roleName: string,
            roleCode: string
        }>('listUserRoles', params)
    }

    /**
     * 根据id删除用户
     */
    updateUserRole = (userId: string, roleId: string) => {
        return this.get<string, { userId: string, roleId: string }>('updateUserRole', {userId, roleId})
    }

    /**
     * 查询用户所有部门信息
     */
    listUserAllDeparts = (userId: string) => {
        return this.get<ISysDepartResp[], { userId: string }>('listUserAllDeparts', {userId})
    }

    /**
     * 修改用户当前部门信息
     */
    updateUserCurrentDepart = (userId: string, departCode: string) => {
        return this.get<string, { userId: string, departCode: string }>('updateUserCurrentDepart', {userId, departCode})
    }

    checkPassword = (checkPasswordReq: CheckPasswordReq) => {
        return this.post<string, CheckPasswordReq>('checkPassword', checkPasswordReq)
    }

    refreshPassword = (refreshPasswordReq: RefreshPasswordReq) => {
        return this.post<string, RefreshPasswordReq>('refreshPassword', refreshPasswordReq)
    }
}

export default new UserApi()